package com.best.oasis.settlement.common.configmapping;

import java.util.HashMap;
import java.util.Map;

import com.best.oasis.settlement.common.entity.department.Department;
import com.best.oasis.settlement.common.entity.employee.Employee;
import com.best.oasis.settlement.common.entity.site.Site;

public class EntitySequenceMapping {

	/**
	 * 默认使用的sequence， 如果实体类不指定sequence，则使用默认的sequence来生成ID
	 */
	public static final String DEFAULT_CODE_SEQUENCE = "default_code_sequence";
	public static final String DEFAULT_ID_SEQUENCE = "default_id_sequence";

	// key为Entity class , value为序列的名字
	public static final Map<Class<?>, String> MAP = new HashMap<Class<?>, String>();

	static {
		//Employee
		MAP.put(Employee.class, "seq_employee_code");
		//Site
		MAP.put(Site.class, "seq_site_code");
		//Department
		MAP.put(Department.class, "seq_department_code");
		
	}
	/**
	 * 根据不同的类，获取Sequence
	 * @param entityClass
	 * @return
	 */
	public static String getSequence(Class<?> entityClass){
		String className = getClassName( entityClass );
		
		String sequence =  MAP.get(className);
		return sequence;
	}
    public static String getClassName( Class<?> entityClass ) 
    {
        String className = entityClass.getName();
        if( className.indexOf('$') > 0 ){
        	className = className.substring(0, className.lastIndexOf('$'));
        }
        if( className.indexOf('.') > 0 ){
        	className = className.substring(className.lastIndexOf('.') + 1,className.length());
        }
        return className;
    }
}
